//
//  HNSH_SignGoodsHeader.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/4/22.
//

#import "HNSH_SignGoodsHeader.h"

@interface HNSH_SignGoodsHeader ()

/* titleLabel */
@property (nonatomic, strong) UILabel *titleLabel;

@end

@implementation HNSH_SignGoodsHeader

//MARK: Cycle Methods
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        [self addAllViews];
        [self addAllLayout];
    }
    return self;
}

//MARK: Myself Methods
- (void)addAllViews{
    UIImageView *icon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"mine_sign_goods_header_icon"]];
    [self addSubview:icon];
    
    [icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.mas_centerY);
        make.left.mas_equalTo(20);
        make.width.height.mas_equalTo(27);
    }];
    
    [self addSubview:self.titleLabel];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitle:@"兑换记录" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor appBlackLabelColor] forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:14];
    [button setImage:[UIImage imageNamed:@"base_nav_show_right"] forState:UIControlStateNormal];
    [self addSubview:button];
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self);
        make.right.mas_equalTo(-20);
        make.width.mas_equalTo(70);
        make.height.mas_equalTo(26);
    }];
    [button HNSH_layoutButtonWithEdgeInsetsStyle:HHZXButtonStyleTextLeft imageTitleSpace:4];
    __weak __typeof(&*self)weakSelf = self;
    [[button rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        if (weakSelf.block) {
            weakSelf.block();
        }
    }];
}

- (void)addAllLayout{
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self);
        make.left.mas_equalTo(51);
        make.height.mas_equalTo(22);
    }];
}

- (UILabel *)titleLabel {
    if (!_titleLabel ) {
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.text = @"汇豆兑换";
        _titleLabel.textColor = [UIColor appBlack333LabelColor];
        _titleLabel.font = [UIFont boldSystemFontOfSize:18];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _titleLabel;
}


@end
